﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DungeonDelver.Common
{
    public class Board<T,U>:IBoard<T,U>
    {
        private Dictionary<int, IBoardColumn<T, U>> columns = new Dictionary<int, IBoardColumn<T, U>>();
        public IBoardColumn<T, U> this[int theIndex]
        {
            get
            {
                if (columns.ContainsKey(theIndex))
                {
                    return columns[theIndex];
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (value == null)
                {
                    if (columns.ContainsKey(theIndex))
                    {
                        columns[theIndex].Board = null;
                        columns.Remove(theIndex);
                    }
                }
                else
                {
                    if (columns.ContainsKey(theIndex))
                    {
                        columns[theIndex].Board = null;
                        columns[theIndex] = value;
                    }
                    else
                    {
                        columns.Add(theIndex, value);
                    }
                    columns[theIndex].Board = this;
                }
            }
        }

        public IEnumerable<int> Columns
        {
            get { return columns.Keys; }
        }
    }
}
